package graphiceditor4robot.plugin;

import java.util.Locale;
import java.util.ResourceBundle;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;


public class Activator extends AbstractUIPlugin {

	public static String ID = "GraphicEditor4Robot";

	// The shared instance
	private static Activator plugin;

	private ResourceBundle resourceBundle;

	public Activator() { }

	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		resourceBundle = ResourceBundle.getBundle("conf/lang", Locale.getDefault());
	}

	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);

	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

	public void showMessage (String message) {
		MessageDialog.openInformation(
				getWorkbench().getWorkbenchWindows()[0].getShell(),
				"Message",
				message);
	}

	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}

	public void reportProblem (IResource resource, int line, String msg, int severity, int priority) {
		try {
			IMarker m = resource.createMarker(IMarker.PROBLEM);
			m.setAttribute(IMarker.LINE_NUMBER, line);
			m.setAttribute(IMarker.MESSAGE, msg);
			m.setAttribute(IMarker.PRIORITY, priority);
			m.setAttribute(IMarker.SEVERITY, severity);
		} catch (CoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void reportWarning (IResource resource, int line, String msg) {
		reportProblem(resource, line, msg, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_LOW);
	}

	public void reportError(IResource resource, int line, String msg) {
		reportProblem(resource, line, msg, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_HIGH);
	}

	public void removeMarkers (IResource resource) {
		try {
			resource.deleteMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
		} catch (CoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}
